package com.gym.controller.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.gym.model.dao.ConnessioneException;
import com.gym.model.dao.DAOUser;
import com.gym.model.dao.DatoNonTrovatoException;
import com.gym.model.dao.MetodoDaoException;

public class DeleteUser extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		int id = Integer.parseInt(request.getParameter("id")); 
		
		try {
			DAOUser dao = new DAOUser();
			
			dao.delete(id); //rimuovo l'utente dal database 
			
			return mapping.findForward("success");
			
		} catch (ConnessioneException | DatoNonTrovatoException | MetodoDaoException e) {
			return mapping.findForward("failure");
		}
		
	}

}
